var express = require('express');
var AnswerModel = require('../db/answerModel')

module.exports = async function (req, res) {
    var questid = req.params.id
    let pintype = req.query.pin
    var response = Array()
    if (parseInt(pintype) === 1 || parseInt(pintype) === 2) {
        await AnswerModel.find({questId: questid, pin: parseInt(pintype)}, function (error, answers) {
            for (let i = 0; i < answers.length; i++) {
                let tmp = {}
                tmp.answerId = answers[i].id
                tmp.pin = answers[i].pin
                tmp.ip = answers[i].ip
                tmp.location = answers[i].location
                tmp.answerTime = answers[i].answerTime
                response.push(tmp)
            }
            if (error) {
                res.status(400).send({
                    status: 400,
                    message: "查找失败"
                })
            }
        })
        res.send(response)
    } else {
        await AnswerModel.find({questId: questid}, function (error, answers) {
            for (let i = 0; i < answers.length; i++) {
                let tmp = {}
                tmp.answerId = answers[i].id
                tmp.pin = answers[i].pin
                tmp.ip = answers[i].ip
                tmp.location = answers[i].location
                tmp.answerTime = answers[i].answerTime
                response.push(tmp)
            }
            if (error) {
                res.status(400).send({
                    status: 400,
                    message: "查找失败"
                })
            }
        })
        res.send(response)
    }

}